package com.hig.risk.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hig.risk.domain.RiskHazardInvestigation;
import com.hig.risk.service.IRiskHazardInvestigationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

/**
 * 安全生产隐患排查治理清单Controller
 * 
 * @author scp
 * @date 2024-09-29
 */
@RestController
@RequestMapping("/risk/investigation")
@Api(tags = "隐患相关接口")
public class RiskHazardInvestigationController extends BaseController
{
    @Autowired
    private IRiskHazardInvestigationService riskHazardInvestigationService;

    /**
     * 查询安全生产隐患排查治理清单列表
     */
    @PreAuthorize("@ss.hasPermi('risk:investigation:list')")
    @GetMapping("/list")
    @ApiOperation("获取隐患列表  查询条件有分页必填跟时间 pageNum=1&pageSize=10&investigationTime=2024-10-01")
    public TableDataInfo list(RiskHazardInvestigation riskHazardInvestigation)
    {
        startPage();
        List<RiskHazardInvestigation> list = riskHazardInvestigationService.selectRiskHazardInvestigationList(riskHazardInvestigation);
        return getDataTable(list);
    }

    /**
     * 导出安全生产隐患排查治理清单列表
     */
    @PreAuthorize("@ss.hasPermi('risk:investigation:export')")
    @Log(title = "安全生产隐患排查治理清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(RiskHazardInvestigation riskHazardInvestigation, HttpServletResponse response)
    {
        List<RiskHazardInvestigation> list = riskHazardInvestigationService.selectRiskHazardInvestigationList(riskHazardInvestigation);
        ExcelUtil<RiskHazardInvestigation> util = new ExcelUtil<RiskHazardInvestigation>(RiskHazardInvestigation.class);
//        return util.exportExcel(list, "安全生产隐患排查治理清单数据");
        util.exportExcel(response,list, "安全生产隐患排查治理清单","安全生产隐患排查治理清单");
        return AjaxResult.success();
    }

    /**
     * 获取安全生产隐患排查治理清单详细信息
     */
    @ApiOperation("获取隐患详情")
    @PreAuthorize("@ss.hasPermi('risk:investigation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(riskHazardInvestigationService.selectRiskHazardInvestigationById(id));
    }

    /**
     * 新增安全生产隐患排查治理清单
     */
    @PreAuthorize("@ss.hasPermi('risk:investigation:add')")
    @Log(title = "安全生产隐患排查治理清单", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("治理上报（新增）governance_progress治理进度字典 查看帮助文档前端--process.env.BASE_URL + '集团公司安全生产重大隐患判定标准（试行）重大隐患判定标准帮助文档.pdf'")
    public AjaxResult add(@RequestBody RiskHazardInvestigation riskHazardInvestigation)
    {
        return toAjax(riskHazardInvestigationService.insertRiskHazardInvestigation(riskHazardInvestigation));
    }

    /**
     * 修改安全生产隐患排查治理清单
     */
    @PreAuthorize("@ss.hasPermi('risk:investigation:edit')")
    @Log(title = "安全生产隐患排查治理清单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("整改治理（修改） 图片上传--/exam-online-api/common/upload")
    public AjaxResult edit(@RequestBody RiskHazardInvestigation riskHazardInvestigation)
    {
        return toAjax(riskHazardInvestigationService.updateRiskHazardInvestigation(riskHazardInvestigation));
    }

    /**
     * 删除安全生产隐患排查治理清单
     */
    @PreAuthorize("@ss.hasPermi('risk:investigation:remove')")
    @Log(title = "安全生产隐患排查治理清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除隐患")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(riskHazardInvestigationService.deleteRiskHazardInvestigationByIds(ids));
    }
}
